package com.example.springboot3.controller;

import com.example.springboot3.common.Result;
import com.example.springboot3.common.enums.RoleEnum;
import com.example.springboot3.entity.Account;
import com.example.springboot3.entity.Admin;
import com.example.springboot3.service.AdminService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class WebController {

    @Resource
    private AdminService adminService;

    /**
     * 登录接口
     */
    @PostMapping("login")
//    接受前端传过来的Json数据 Account是通用角色
    public Result login(@RequestBody Account account){
        Account loginAccount = null;
//        判断只有管理员身份才能进入
        if (RoleEnum.ADMIN.name().equals(account.getRole())){
//            信息返回出来 赋值给loginAccount
            loginAccount = adminService.login(account);
        }
        return Result.success(loginAccount);
    }
}
